using Unity.Entities;
using Unity.Mathematics;

namespace Game.Core
{
    public partial struct AttackableRefreshJob : IJobEntity
    {
        public float DeltaTime;
        void Execute(ref Attackable attackable, ref PropertyData data)
        {
            if ((data.Refresh & PropertyRefresh.Base) == PropertyRefresh.Base ||
                (data.Refresh & PropertyRefresh.Attackable) == PropertyRefresh.Attackable)
            {
                PropertyUtil.RefreshAttackable(ref attackable, in data); 
            }

            if ((data.Refresh & PropertyRefresh.Init) == PropertyRefresh.Init)
            {
                attackable.Detail.CurAbilityPoint = attackable.Detail.MaxAbilityPoint;
            }
            
            attackable.Detail.CurAbilityPoint =
                math.min(attackable.Detail.CurAbilityPoint + attackable.Detail.AbilityRecover * DeltaTime,
                    attackable.Detail.MaxAbilityPoint);

            if (data.Refresh == PropertyRefresh.Attackable)
                data.Refresh = PropertyRefresh.None;
        }
    }
}